<?php $this->load->view('shared/_handler') ?>
<link href="<?php echo styleJquery() ?>" rel="stylesheet"/>
<form method="POST" action="<?php echo base_url() ?>usuario/save">
    <input type="hidden" value="<?php echo $user->usu_codigo; ?>" name="ip_codigo"/>
    <div class="input-group">
        <span class="input-group-addon">Nome</span>
        <input type="text" name="ip_nome" class="form-control" required="true" value="<?php echo $user->usu_nome; ?>" >
        <span class="input-group-addon">Sobre Nome</span>
        <input type="text" name="ip_sobre_nome" class="form-control" value="<?php echo $user->usu_sobre_nome; ?>">
    </div><br/>
    <div class="input-group">
        <span class="input-group-addon">Telefone</span>
        <input type="text" name="ip_telefone" class="form-control input_fone" value="<?php echo $user->usu_telefone; ?>">
        <span class="input-group-addon">Celular</span>
        <input type="text" name="ip_celular" class="form-control input_fone" value="<?php echo $user->usu_celular; ?>">
    </div><br/>
    <div class="input-group">
        <span class="input-group-addon">Email</span>
        <input type="email" name="ip_email" class="form-control" value="<?php echo $user->usu_email; ?>">
        <span class="input-group-addon">Data de Nascimento</span>
        <input type="text" name="ip_data_nascimento" class="form-control input_data" value="<?php echo formata_data_com_barra($user->usu_data_nascimento); ?>">
    </div><br/>
    <div class="input-group">
        <span class="input-group-addon">Endereco</span>
        <input type="text" name="ip_endereco" class="form-control"  value="<?php echo $user->usu_endereco; ?>">
        <span class="input-group-addon">nº</span>
        <input type="number" name="ip_numero" class="form-control"  style="width: 100px;"value="<?php echo $user->usu_numero; ?>">
        <span class="input-group-addon">Bairro</span>
        <input type="text" name="ip_bairro" class="form-control" value="<?php echo $user->usu_numero; ?>">
        <span class="input-group-addon">CEP</span>
        <input type="text" name="ip_cep" class="form-control input_cep" value="<?php echo $user->usu_cep; ?>">
    </div><br/>
    <div class="input-group">
        <span class="input-group-addon">Estado</span>
        <select id="cod_estados" class="form-control">
            <?php
            foreach ($estados as $key => $estado) {
                echo "<option value='$key'>$estado</option>";
            }
            ?>
        </select>
        <span class="input-group-addon">Cidade</span>
        <select name="ip_cidade" id="cod_cidades" class="form-control"  >
            <option value="">-- Escolha um estado --</option>
        </select>
    </div><br/>
    <input type="submit" class="btn btn-default" value="Salvar">
</form>

<?php $this->load->view('shared/_footer') ?>

<script type="text/javascript">
    $(function() {
        $('#cod_estados').change(function() {
            if ($(this).val()) {
                $('.carregando').show();
                $.getJSON('<?php echo base_url() ?>ajax/cidades/' + $(this).val(), function(j) {
                    var options = '<option value=""></option>';
                    for (var i = 0; i < j.length; i++) {
                        options += '<option value="' + j[i].id + '">' + j[i].nome + '</option>';
                    }
                    $('#cod_cidades').html(options).show();
                });
            } else {
                $('#cod_cidades').html('<option value="">“ Escolha um estado“</option>');
            }
        });
    });
    window.onload = function() {
        $(".input_fone").mask("+55 (99) 9999-9999");
        $(".input_cep").mask("99999-999");
        $(".input_data").datepicker({dateFormat: 'dd/mm/yy'});
    };
</script>

